<!-- announcementAdd -->
<?
global $DB, $sess, $sPOST, $sGET;
include_once "settings.inc.php";

if(isset($_POST))
{
	$sql = "SELECT * FROM " . _MODULE_NAME . " WHERE id=".$sGET['id'];
	$row = $DB->fetchArray($sql);
	if(!is_array($row[0]))
		git("?"._MODULE_NAME.".list");

	/*
	if($row[0]['picture'] == "")
		$pictureContent = "<input type=\"file\" name=\"picture\" id=\"picture\" />";
	else
		$pictureContent = "<a href=\"../pictures/" . _MODULE_NAME . "/bigs/" . $row[0]['picture'] . "\" class=\"galeri\"><img src=\"../pictures/" . _MODULE_NAME . "/thumbs/" . $row[0]['picture'] . "\" /></a> <img src=\"images/iconDelete.png\" id=\"" . $row[0]['id'] . "\" class=\"pictureDelete\" title=\"Sil\" />";
	*/
	
	if($row[0]['selected'])
		$selectedStatus = " checked='checked'";
	else
		$selectedStatus = "";
}
?>

<style>
	label		{	font-family:Tahoma; font-size:12px; font-weight:bold; text-align:right;	}
	textarea 	{	position:relative; min-height:60px; background:#fff;	}
	.etiket		{	width:150px; min-height:30px; line-height:30px;	}
	.pictureDelete {	cursor: pointer;}
	.pictureContainer {	float:left; margin:5px; position: relative; background: #888; padding: 5px; border-radius: 5px; min-height:97px; min-width:142px;	}
	.pictureContainer > a {	text-decoration: none; clear:both;}
	.pictureContainer > a > img {	border:5px solid #eee; max-height:85px; min-height:85px; min-width:113px;}
</style>


<script>
	$(function(){
		$('.pictureDelete').live("click",function(event){
			if(confirm("Bu resmi silmek istediğinizden emin misiniz?"))
			{
				var id = $(event.target).attr("pic_id");
				var result = toPost("?<?=_MODULE_NAME;?>.otherProcess","action=1&process=deleteProjectPicture&id="+id);
				switch(result)
				{
					case "OK":
						$('#pictureContainer_'+id).remove();
					break;

					case "ERROR":
						alert("Resim bir hatadan dolayı silinemedi.");
					break;

					default:
						alert(result);
					break;
				}
			}
		});
		
		
		// Sıralama işlemleri fonksiyonları başlar
		$('.rowOrder').bind("change", function(){
			var id = parseInt($(this).attr("id"));
			var newRow = parseInt($(this).val());
			var result = toPost("?<?=_MODULE_NAME;?>.otherProcess","action=1&process=changeRowProjectPicture&id="+id+"&newRow="+newRow);
			if(result == "OK")
				location.reload(true);
			else if(result == "ERROR")
			{
				alert("Kayıt sıralaması başarısız oldu.");
				location.reload(true);
			}
			else if(result != "NONE")
				alert(result);
		});
		
		$('.rowOrder').bind("keyup", function(e){
			if(e.keyCode == 13){
				var id = parseInt($(this).attr("id"));
				var newRow = parseInt($(this).val());
				var result = toPost("?<?=_MODULE_NAME;?>.otherProcess","action=1&process=changeRowProjectPicture&id="+id+"&newRow="+newRow);
				if(result == "OK")
					location.reload(true);
				else if(result == "ERROR")
				{
					alert("Kayıt sıralaması başarısız oldu.");
					location.reload(true);
				}
				else if(result != "NONE")
					alert(result);
			}
		});
		// Sıralama işlemleri fonksiyonları biter
		

		$('#loadPictures').ajaxForm({
				    beforeSend: function() {
	       	$("#loadPictureButton").attr("disabled","disabled");			
				$("#projectPicturex").hide();
				$("#projectLoadingFile").show();
		    },
			complete: function(xhr) {
				var data = xhr.responseText;
				switch(data)
				{
					case "OK":
						var list = toPost("?<?=_MODULE_NAME;?>.otherProcess","action=1&process=getProjectPictures&id=<?=$row[0]['id'];?>");
						$("#projectPictureContainer").html(list);
					break;

					case "ERROR":
						alert("Proje resmi bir hatadan dolayı yüklenemedi.");
					break;

					default:
						alert(data);
					break;
				}
				$("#projectPicturex").val("");
				$("#projectPicturex").show();
				$("#projectLoadingFile").hide();
				$("#loadPictureButton").removeAttr("disabled");
			}
		}); 

	});
</script>


<h2>PROJE GÜNCELLE</h2>
<form method="post" action="?<?=_MODULE_NAME?>.editProcess" method="POST" enctype="multipart/form-data" >
	<fieldset>
		<!-- <legend>Duyuru Ekleme</legend> -->
		<input type="hidden" name="id" id="id" value="<?=$row[0]['id']?>" />
		<table cellpadding="0" cellspacing="3" border="0" style="width:100%;">
			<tr>
				<td class="right etiket"><label for="category_idx">Proje Kategorisi : </label></td>
				<td>
					<select name="category_id" id="category_idx">
						<option value="">Seçiniz...</option>
						<?php
							$catSql = "SELECT * FROM " . _MODULE_NAME . "Category ORDER BY row ASC";
							$categorys = $DB->fetchArray($catSql);
							if(is_array($categorys[0]))
								foreach ($categorys as $cat) {
									if($cat['id'] == $row[0]['category_id'])
										echo "<option value='" . $cat['id'] . "' selected='selected'>" . $cat['category_name'] . "</option>";
									else
										echo "<option value='" . $cat['id'] . "'>" . $cat['category_name'] . "</option>";
								}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td class="right etiket"><label for="project_typex">Proje Tipi : </label></td>
				<td>
					<select name="project_type" id="project_typex">
						<option value="">Seçiniz...</option>
						<?php
							$typeSql = "SELECT * FROM " . _MODULE_NAME . "Type ORDER BY row ASC";
							$types = $DB->fetchArray($typeSql);
							if(is_array($types[0]))
								foreach ($types as $type) {
									if($type['id'] == $row[0]['project_type'])
										echo "<option value='" . $type['id'] . "' selected='selected'>" . $type['type_name'] . "</option>";
									else
										echo "<option value='" . $type['id'] . "'>" . $type['type_name'] . "</option>";
								}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td class="right etiket"><label for="project_namex">Proje Adı: </label></td>
				<td><input class="mf" name="project_name" id="project_namex" type="text" value="<?=$row[0]['project_name']?>" /></td>
			</tr>
			<tr>
				<td class="right etiket"><label for="contentx">İçerik : </label></td>
				<td><textarea name="content" id="contentx" class="tinymceMini" style="min-height:250px;"><?=$row[0]['content']?></textarea></td>
			</tr>
			<tr>
				<td class="right etiket"><label for="selectedx">İçerik : </label></td>
				<td><input type="checkbox" value='1' name="selected" id="selectedx" <?=$selectedStatus; ?> /></td>
			</tr>
			<tr>
				<td class="etiket">&nbsp;</td>
				<td class="left">
					<input class="button" type="submit" value="Güncelle" />
					<input class="button geri" type="button" value="Geri" />
				</td>
			</tr>
		</table>
	</fieldset>
</form>

<!-- Picture Loader Start -->
<fieldset>
	<form method="post" action="?<?=_MODULE_NAME?>.otherProcess" method="POST" id="loadPictures" enctype="multipart/form-data">
		<input type="hidden" name="project_id" value="<?=$row[0]['id'];?>" />
		<input type="hidden" name="process" value="loadPicture" />
		<input type="hidden" name="action" value="1" />
		<table cellpadding="0" cellspacing="3" border="0" style="width:100%;">
			<tr>
				<td class="right etiket"><label for="projectPicturex">Proje Resmi : </label></td>
				<td>
					<table cellpadding="0" cellspacing="0" border="0">
						<tr>
							<td><input type="file" name="projectPicture" id="projectPicturex" /><img src="images/loadingFile.gif" id="projectLoadingFile" style="display:none;" />
							</td>
							<td><input type="submit" value="Yükle" class="button" id="loadPictureButton" /></td>
						</tr>
					</table>
				</td>
			</tr>
			
		</table>
	</form>
</fieldset>
<!-- Picture Loader End -->

<!-- Pictures Container start -->
<?
$pictureSql = "SELECT * FROM "._MODULE_NAME."Picture WHERE project_id='". $row[0]['id'] ."' ORDER BY row DESC";
$pictureExe = $DB->fetchArray($pictureSql); 
?>
<fieldset id="projectPictureContainer">
<?
	if(is_array($pictureExe[0]))
	{
		foreach ($pictureExe as $picVal) 
		{
			echo "\n<div class=\"pictureContainer\" id=\"pictureContainer_". $picVal['id'] ."\">
							<a href=\"../pictures/" . _MODULE_NAME . "/bigs/" . $picVal['picture'] . "\" class=\"galeri\">
								<img src=\"../pictures/" . _MODULE_NAME . "/thumbs/" . $picVal['picture'] . "\" />
							</a> 
							<img src=\"images/iconDelete.png\" pic_id=\"" . $picVal['id'] . "\" class=\"pictureDelete\" title=\"Sil\" />
							<input type=\"\" value=\"".intVal($picVal['row'])."\" id=\"".$picVal['id']."_pic\" class=\"rowOrder\" style=\"float:right; position:absolute; top:5px; right:-5px; width:20px;\" />
						</div>";
		}
	}
	else
	{
		echo "<p>Hiç proje resmi eklenmemiş.</p>";
	}
?>
</fieldset>
<!-- Picture Container End -->

<!-- /announcementAdd -->